package com.e3.web.index.client;

import com.e3.web.core.client.GXTHelper;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

public class MainFrameUI extends LayoutContainer {
	
	private Widget northPanel;
	
	private ContentPanel contentPanel;
	
	private ContentPanel centerPanel;

	private MainStatusBar statusBar;
	
	private MainWorkspace workspacePanel;
	
	private MainFrameServiceAsync service = MainFrameService.Util.getInstance();

	@Override
	protected void onRender(Element parent, int index) {
		super.onRender(parent, index);
		
		//north panel to show the corporate's icon and others.
		BorderLayoutData bld = new BorderLayoutData(LayoutRegion.NORTH);
		bld.setSize(30);
		getContentPanel().add(getNorthPanel(),bld);
		
		//center panel to show the module's UI.
		BorderLayoutData ld = new BorderLayoutData(LayoutRegion.CENTER);
		getContentPanel().add(getCenterPanel(),ld);

		getContentPanel().setBottomComponent(getStatusToolBar());
		
		String name = GXTHelper.getClientSession().getCorpName();
		if(name == null){
			name = GXTHelper.getClientSession().getCorpCode();
		}
		getStatusToolBar().setCompany(name);
		name = GXTHelper.getClientSession().getUserName();
		if(name == null){
			name = GXTHelper.getClientSession().getUserCode();
		}

	}
	private Widget getNorthPanel(){
		if(northPanel == null){
			northPanel = new HTMLPanel("<img alt=\"\" src=\"Resources/images/indextop.png\">");
		}
		return northPanel;
	}
	
	public ContentPanel getContentPanel(){
		if(contentPanel == null){
			contentPanel = new ContentPanel(new BorderLayout());
		}
		return contentPanel;
	}
	
	public ContentPanel getCenterPanel(){
		if(centerPanel == null){
			centerPanel = new ContentPanel();
//			ld.setMargins(new Margins(0,3,3,3));
			centerPanel.setHeaderVisible(false);
//			centerPanel.setFrame(true);
			BorderLayout layout = new BorderLayout();
			centerPanel.setLayout(layout);
			
			BorderLayoutData bld = new BorderLayoutData(LayoutRegion.CENTER);
			centerPanel.add(getWorkspacePanel(), bld);
		}
		return centerPanel;
	}
	
	public MainStatusBar getStatusToolBar(){
		if(statusBar==null){
			statusBar = new MainStatusBar();
		}
		return statusBar;
	}
	
	public MainWorkspace getWorkspacePanel(){
		if(workspacePanel == null){
//			/workspacePanel = new MainWorkspace(this);
		}
		return workspacePanel;
	}
	
	public MainFrameServiceAsync getService(){
		return service;
	}

}
